$(function(){
	
	$('.head-bottom ul>li').on('click',function(){
		 $(this).siblings('li').removeClass('selected');
		 $(this).addClass('selected');
	});
	
	//
	$('#yc_intag ul li').click(function(){
		var index = $(this).index();
		$(this).addClass('yc-li').siblings().removeClass('yc-li');
		$('.yc_incont:eq('+index+')').css('display','block').siblings().css('display','none');
	});
	
	 //图片切换
	var num =0 ;
	var count=0
	var changeImg = function(){
		var imgs = $('.leftbar-left img');
		count = num;
		$(imgs[count]).css('display','block');
		$('.left-img-num li:eq('+count+')').addClass('img-current-num');
		$('.left-img-num li:eq('+count+')').siblings('li').removeClass('img-current-num');
		
		//前一张隐藏掉
		if(count > 0){
			$(imgs[count-1]).css('display','none');
		}
		
		//一圈之后回到0，最后一张隐藏掉
		if(count == 0){
			$(imgs[imgs.length-1]).css('display','none');
		}
		++ num;
		//最后一张之后在从头开始
		if(count  == imgs.length-1){
			num = 0;
		}
		var newsId = $('.leftbar-left img:visible').parent().next().text();
		var newsTitle = $('.leftbar-left img:visible').parent().next().next().text();
		$("#imgNewsTitle").text(newsTitle).attr("title",newsTitle).attr("href","public/news/detail/"+newsId);
	};
	setInterval(changeImg, 2000);//图片轮播

	//最新注册用户
	var url = "public/selectLastRegister";
	ajaxResult(url,{},function(success,result){
		if(success){
			$("#lastRegisterUser").empty();
			var data = result.obj;
			var $ul = $("<ul style=\"float: left;\"></ul>");
			for(var i = 0 ; i < data.length ; i++){
				var $li = $("<li></li>");
				var $div1 = "<div style=\"width: 56px;\">";
						$div1 +="<a href=\"public/userLand/"+data[i].id+"\" title=\""+data[i].chName+"\" target=\"_blank\">";
						$div1 +="<img  alt=\""+data[i].chName+"\" title=\""+data[i].chName+"\" src=\"public/user/showPicture/"+data[i].id+"\"/>";
						$div1 +="</a></div>";
				var	$div2 = "<div style=\"width:56px;height: 18px;font-size: 12px;text-align: center;margin-left:8px;\">";
						$div2 +="<a href=\"public/userLand/"+data[i].id+"\" title=\""+data[i].chName+"\" target=\"_blank\">"+data[i].chName;
						$div2 +="</a></div>";
				$li.append($div1).append($div2)
				$ul.append($li);
			}
			$("#lastRegisterUser").append($ul);
		}else{
			$("#lastRegisterUser").html("获取用户失败");
		}
	});
	
	/**
	 * 最新动态
	 */
	 url = "public/showMoments";
	 ajaxAsyncResult(url,{},function(success,result){
		 if(success){
			$(".new-moments-list ul>li").not(":eq(0)").remove();
			 var data = result.obj;
			 for(var i = 0;i<data.length;i++){
					 var content = "<li  style=\"height: 52px;\">";
					 		content += "<div class=\"moments-div\">";
					 		content += "<a  title=\""+data[i].chName+"\"  target=\"_blank\" href=\"public/userLand/"+data[i].creater+"\" style=\"color: #00BC3E;\">";
					 		content +="<img alt=\"\" src=\"public/user/showPicture/"+data[i].creater+"\" />";
					 		content += "</a></div>";
					 		content += "<div class=\"moments-div-content\">";
					 		content += "<div class=\"moments-div-chName\">";
					 		content += "<a title=\""+data[i].chName+"\"  target=\"_blank\" href=\"public/userLand/"+data[i].creater+"\" style=\"color: #00BC3E;\">"+data[i].chName+":</a>";
					 		content += "<span>"+(data[i].content.length >15?data[i].content.substr(0,15)+"...":data[i].content)+"</span>";
					 		content += "</div>";
					 		content += "<div class=\"moments-div-detail\">";
					 		content += "<span style=\"float: left;height:100%;\">";
					 		content += "<img src=\"images/zan.png\" class=\"moments-div-detail-img\"  />";
					 		content += "<span style=\"float: left;\">("+data[i].commentNum+")</span>";
					 		content += "</span>";
					 		content += "<span class=\"moments-div-date\">"+formatDateStyle(data[i].createDate)+"</span>";
					 		content += "</div>";
					 		content += "</div>";
					 		content += "</li>";
				 $(".new-moments-list ul").append(content);
			 }
		 }
	 });
	 
	 /**
	  *发送修改密码地址到邮箱
	  */
	 $("#updatePwdSendEmail").on("click",function(){
		 	var username = $('#username').val();
		 	if(!username && username !=0){
		 		$('.errorMsg').html('用户名不能为空!');
		 		return;
		 	}
		 	if(!email && email !=0){
		 		$('.errorMsg').html('邮箱不能为空!');
		 		return;
		 	}
		 	 url = "public/user/updatePwdSendEmail";
		 	 var params = {'email':email};
			 ajaxAsyncResult(url,params,function(success,result){
					$.util.alert(result.message);
			 });
	 });
	 
	/**
	 * 首页和搜索页面的搜索
	 */
	 $("#search-btn,#search-query-btn").on("click",function(){
		 var searchText = $("#searchText").val();
		 if(!searchText){//搜索内容为空
			 location.href = "public/pearch";
		 }else{
			 location.href = "public/searchList?searchText="+searchText;
		 }
	 });
	 
	 
	 /**
	  * 结果页面的搜索
	  */
	 $("#search-list-btn").on("click",function(){
		 var searchText = $("#searchText").val();
		 if(!searchText){//搜索内容为空
			 location.href = "public/index";
		 }else{
			 location.href = "public/searchList?searchText="+searchText;
		 }
	 });
	 
	 /**
	  * enter快捷键
	  */
	 $("#search-list-btn").keydown(function(event){
		 if(event.keyCode == 13){
			 alert('你按下了Enter'); 
		 }
		});
	 
	 //首页图书获取焦点
/*	 $(".book-list-detail li img").mouseover(function(){
		 console.info($(this).attr("width"));
		 $(this).attr({width:"200",height:"210"});
	 });*/
		/*var url = "public/listCategory.shtml";
		ajaxResult(url,{},function(flag,obj){
		});*/
		
		//后台开发
		/* url = "public/listArticleType.shtml";
		ajaxResult(url,{},function(flag,result){
			var data = result.obj;
			for(var i = 0 ; i<data.length ; i++){
				$('#article1').append("<li>"+data[i].articleTitle+"</li>");
			}
		});*/
	
	/*
			listResourceFile();
			listArticle();
			$('#yc_intag ul li').click(function(){
					var index = $(this).index();
					$(this).addClass('yc-li').siblings().removeClass('yc-li');
					$('.yc_incont:eq('+index+')').css('display','block').siblings().css('display','none');
			});
			
			var showLi = $('#versionShow .show');
			$.each(showLi,function(index,value){
				if(index != 0){
					var $show = $(value);
					$show.siblings().hide();
				}
			});
			
			$('.show').click(function(){
					$(this).siblings().fadeToggle("slow");
					var expand = $(">span",this).eq(1).html();
					if(expand == '+' ){
						$(">span",this).eq(1).html('-');
					}else{
						$(">span",this).eq(1).html('+');
					}
			});
	});
			
		function listArticle(){
			//文章
			$.ajax({
				type:'POST',
				url:'listArticle',
				dataType:'json',
				success:function(data){
					if(data && data.success){
						$('#article').empty();
						for(var i=0;i<data.object.length;i++){
							if(data.object[i].articleTitle.length >36){
								var articleTitle = data.object[i].articleTitle.substring(1,36);
								$('#article').append("<p><a target=\"_blank\" href=\"expose/article/detail/"+data.object[i].id+"\">"+articleTitle+"...</a></p>");
							}else{
								$('#article').append("<p><a target=\"_blank\" href=\"expose/article/detail/"+data.object[i].id+"\">"+data.object[i].articleTitle+"</a></p>");
							}
						}
					}else{
						$('#article').append("<li>出错啦!</li>");
					}
				}
			});
		}
		
		function listResourceFile(){
			//最新下载
			$.ajax({
				type:'POST',
				url:'listResourceFile',
				dataType:'json',
				success:function(data){
					if(data && data.success){
							$('#rfile').empty();
						for(var i=0;i<data.object.length;i++){
							if(data.object[i].resourceTitle.length >30){
								var resourceTitle = data.object[i].resourceTitle.substring(1,30);
								$('#rfile').append("<li><a target=\"_blank\" href=\"expose/resource/detail?id="+data.object[i].id+"\">"+resourceTitle+"</a></li>");
							}else{
								$('#rfile').append("<li><a target=\"_blank\" href=\"expose/resource/detail?id="+data.object[i].id+"\">"+data.object[i].resourceTitle+"</a></li>");
							}
						}
					}else{
						$('#rfile').append("<li>出错啦!</li>");
					}
				}
			});
		}

		
setInterval("listArticle()",1000*60*30);
setInterval("listResourceFile()",1000*60*30);
*/

});

/**js收藏*/
function addfavorite() {
	  var url = window.location.href;
	 var title = document.title;
	 try {
	 	   window.external.addFavorite(url, title);
	 }catch (e) {
	 	    try {
	 	           window.sidebar.addPanel(title, url, "");
	 	    }catch (e) {
	 	        $.util.alert("抱歉，您所使用的浏览器无法完成此操作，请使用Ctrl+D进行添加");
	 	     }
	 }
}

